class_name CardTooltipPopup
extends Control

@export var bg_color: Color = "000000b0"

@onready var tooltip_cards: CenterContainer = %TooltipCards
@onready var card_description: RichTextLabel = %CardDescription
@onready var background: ColorRect = %Background

func _ready() -> void:
	hide_tooltip()
	background.color = bg_color
	
func _on_gui_input(event: InputEvent) -> void:
	if event.is_action_pressed("left_mouse"):
		hide_tooltip()

func show_tooltip(card: Card) -> void:
	var new_card : CardMenuUI = AutoLoader.CARD_MENU_UI_SCENE.instantiate()
	tooltip_cards.add_child(new_card)
	new_card.card = card
	new_card.tooltip_requested.connect(hide_tooltip.unbind(1))
	card_description.text = card.get_default_tooltip()
	show()
	

func hide_tooltip() -> void:
	if not visible:
		return
	for child in tooltip_cards.get_children():
		child.queue_free()
	hide()
